home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / PKTSEND.ASM < prev    next >
Assembly Source File  |  1992-01-23  |  9KB  |  456 lines

  1. version    equ    1
  2.  
  3. ;  Copyright, 1989-1992, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     org    2h
  24. phd_memsize    label    word
  25.  
  26.     org    80h
  27. phd_dioa    label    byte
  28.  
  29.     org    100h
  30. start:
  31.     jmp    start_1
  32. copyleft_msg    label    byte
  33.  db "Packet sender version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  34.  db "This program is free software; see the file COPYING for details.",CR,LF
  35.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  36. crlf_msg    db    CR,LF,'$'
  37.  
  38. int_pkt    macro
  39.     pushf
  40.     cli
  41.     call    their_isr
  42.     endm
  43.  
  44. their_isr    dd    ?
  45. packet_int_no    db    ?,?,?,?
  46. handle        dw    ?
  47. packet_flag    dw    0
  48. repeat_switch    db    ?
  49. quiet_switch    db    ?
  50. async_switch    db    ?
  51.  
  52. send_count    dw    ?,?
  53. pkt_count    dd    ?
  54.  
  55. async_iocb1    iocb    <0, 0, DONE>    ;Two iocbs
  56. async_iocb2    iocb    <0, 0, DONE>
  57.  
  58. signature    db    'PKT DRVR',0
  59. signature_len    equ    $-signature
  60.  
  61. no_signature_msg    db    "No packet driver at that address",'$'
  62. usage_msg    db    "usage: pktsend <packet_int_no> [-r [-q] | -n number] [-f filename | -l length | packet]",'$'
  63. sending_msg    label    byte
  64.     db    "Press space to re-send packet(s).  Any other key exits.",CR,LF,'$'
  65. repeat_msg    label    byte
  66.     db    "Sending repeat packets.  Any key exits.",CR,LF,'$'
  67. file_not_found    db    "File not found",'$'
  68. read_trouble    db    "Trouble reading the file",'$'
  69. non_number_msg    db    "Non-numeric input found",'$'
  70. mem_trashed_msg    db    CR,LF,"Found trashed memory at ",'$'
  71.  
  72. line_buffer    db    128 dup(?)
  73.  
  74. usage_error:
  75.     mov    dx,offset usage_msg
  76. error:
  77.     mov    ah,9
  78.     int    21h
  79.     int    20h
  80.  
  81. start_1:
  82.     mov    dx,offset copyleft_msg
  83.     mov    ah,9
  84.     int    21h
  85.  
  86.     mov    si,offset phd_dioa+1
  87.     cmp    byte ptr [si],CR    ;end of line?
  88.     je    usage_error
  89.  
  90.     mov    di,offset packet_int_no
  91.     call    get_number
  92.     mov    word ptr pkt_count,1
  93.     mov    word ptr pkt_count+2,0
  94.  
  95. another_switch:
  96.     call    skip_blanks
  97.  
  98.     mov    al,[si]            ;did the give the packet inline?
  99.     cmp    al,'-'            ;did they specify a switch?
  100.     jne    not_switch
  101.     cmp    byte ptr [si+1],'r'    ;did they specify '-r'?
  102.     je    got_repeat_switch
  103.     cmp    byte ptr [si+1],'q'    ;did they specify '-q'?
  104.     je    got_quiet_switch
  105.     cmp    byte ptr [si+1],'n'    ;did they specify '-n'?
  106.     je    got_number_switch
  107.     cmp    byte ptr [si+1],'l'    ;did they specify '-l'?
  108.     je    got_length_switch
  109.     cmp    byte ptr [si+1],'f'    ;did they specify '-f'?
  110.     je    start_file
  111.     cmp    byte ptr [si+1],'a'    ;did they specify '-a'?
  112.     je    got_async_switch
  113.     jmp    usage_error        ;no, must be an error.
  114. got_repeat_switch:
  115.     mov    repeat_switch,1
  116.     add    si,2
  117.     jmp    another_switch
  118. got_quiet_switch:
  119.     mov    quiet_switch,1
  120.     add    si,2
  121.     jmp    another_switch
  122. got_number_switch:
  123.     add    si,2
  124.     mov    di,offset pkt_count
  125.     call    get_number
  126.     jmp    another_switch
  127. got_length_switch:
  128.     add    si,2
  129.     mov    di,offset send_count
  130.     call    get_number
  131.     mov    di,offset our_buffer
  132.     add    di,send_count
  133.     jmp    start_gotit
  134. got_async_switch:
  135.     mov    async_switch,1
  136.     add    si,2
  137.     jmp    another_switch
  138. not_switch:
  139.     jmp    start_inline        ;yes.
  140.  
  141. start_file:
  142.     add    si,2
  143.     call    skip_blanks
  144.     mov    dx,si            ;remember where the filename starts.
  145. start_3:
  146.     lodsb
  147.     cmp    al,' '
  148.     je    start_4
  149.     cmp    al,CR
  150.     jne    start_3
  151. start_4:
  152.     dec    si
  153.     mov    byte ptr [si],0
  154.  
  155. ;read the packet bytes from the named file.
  156.  
  157.     mov    ax,3d00h        ;open for reading.
  158.     int    21h
  159.     jnc    file_found
  160.     mov    dx,offset file_not_found
  161.     jmp    error
  162.  
  163. file_found:
  164.     mov    handle,ax
  165.     mov    di,offset our_buffer
  166. start_line:
  167.     mov    si,offset line_buffer
  168. again_line:
  169.     mov    ah,3fh            ;read a single character.
  170.     mov    bx,handle
  171.     mov    cx,1
  172.     mov    dx,si
  173.     int    21h
  174.     jnc    no_trouble
  175.     mov    dx,offset read_trouble
  176.     jmp    error
  177.  
  178. no_trouble:
  179.     cmp    ax,1            ;did we actually read one?
  180.     je    not_eof
  181.     cmp    si,offset line_buffer    ;did we read anything this time?
  182.     je    start_file_eof        ;no, it's really eof this time.
  183.     mov    [si],byte ptr CR    ;add an extra CR, just in case.
  184.     jmp    short done_reading
  185. not_eof:
  186.     lodsb                ;get the character we just read.
  187.     cmp    al,LF            ;got the LF?
  188.     jne    again_line        ;no, read again.
  189.  
  190. done_reading:
  191.     mov    si,offset line_buffer
  192. again_chars:
  193.     call    get_number
  194.     jnc    got_a_number
  195.     mov    dx,offset non_number_msg
  196.     jmp    error
  197. got_a_number:
  198.     inc    di
  199.     call    skip_blanks
  200.     cmp    al,CR
  201.     jne    again_chars        ;keep going to the end.
  202.  
  203.     jmp    start_line
  204.  
  205. start_file_eof:
  206.     mov    ah,3eh            ;close the file.
  207.     mov    bx,handle
  208.     int    21h
  209.     jmp    short start_gotit
  210.  
  211. start_inline:
  212. ;read the packet bytes off the command line.
  213.     mov    di,offset our_buffer-1
  214. start_2:
  215.     inc    di            ;pre-increment
  216.     call    get_number        ;get a byte.
  217.     jnc    start_2            ;keep going to the end.
  218.  
  219. start_gotit:
  220.  
  221.     sub    di,offset our_buffer
  222.     mov    send_count,di
  223.  
  224.     mov    sp,offset start        ;now that we're finished with
  225.                     ;the parameters, put our stack there.
  226.  
  227.     mov    di,offset our_buffer + GIANT * 2
  228.     inc    di
  229.     and    di,not 1
  230.     push    cs
  231.     pop    es
  232. init_memory:
  233.     mov    ax,055aah        ;initialize a segment to 055aah.
  234.     mov    cx,di
  235.     neg    cx
  236.     shr    cx,1
  237.     stosw
  238.     sub    cx,2
  239.     rep    stosw
  240.     mov    ax,es
  241.     add    ax,1000h
  242.     mov    es,ax
  243.     add    ax,1000h
  244.     cmp    ax,phd_memsize        ;don't go past the end of memory.
  245.     jbe    init_memory
  246.  
  247.     mov    ah,35h            ;get their packet interrupt.
  248.     mov    al,packet_int_no
  249.     int    21h
  250.     mov    their_isr.offs,bx
  251.     mov    their_isr.segm,es
  252.  
  253.     lea    di,3[bx]
  254.     mov    si,offset signature
  255.     mov    cx,signature_len
  256.     repe    cmpsb
  257.     je    signature_ok
  258.     jmp    no_signature_err
  259. signature_ok:
  260.  
  261.     push    ds
  262.     mov    ax,1ffh            ;driver_info
  263.     int_pkt
  264.     pop    ds
  265.     call    fatal_error
  266.  
  267.     mov    ah,2            ;access all packets.
  268.     mov    al,ch            ;their class from driver_info().
  269.     mov    bx,dx            ;their type from driver_info().
  270.     mov    dl,cl            ;their number from driver_info().
  271.     mov    cx,0            ;type length of zero.
  272.     push    cs            ;es:di -> our receiver.
  273.     pop    es
  274.     mov    di,offset our_recv
  275.     int_pkt
  276.     call    fatal_error
  277.     mov    handle,ax
  278.  
  279.     cmp    repeat_switch,0
  280.     je    load_count
  281.     mov    dx,offset repeat_msg
  282.     mov    ah,9
  283.     int    21h
  284. load_count:
  285.     mov    ax,word ptr pkt_count
  286.     mov    dx,word ptr pkt_count+2
  287.  
  288. send_again:
  289.     push    ax
  290.     push    dx
  291.     mov    ah,4            ;send_pkt
  292.     mov    si,offset our_buffer    ;ds:si -> buffer.
  293.     mov    cx,send_count
  294.     cmp    async_switch,0        ;async?
  295.     je    send_pkt        ;no
  296.     mov    ah,12            ;as_send_pkt
  297. find_iocb:                ;find a free iocb
  298.     mov    di,offset async_iocb1    ;try first
  299.     test    [di].flags,DONE        ;free?
  300.     jnz    got_iocb        ;yes
  301.     mov    di,offset async_iocb2    ;no, try second
  302.     test    [di].flags,DONE        ;free?
  303.     jz    find_iocb        ;no, try first again
  304. got_iocb:                ;set up iocb
  305.     mov    word ptr [di].buffer,si
  306.     mov    word ptr [di].buffer+2,ds
  307.     mov    es,word ptr [di].buffer+2
  308.     mov    [di].len,cx
  309.     mov    [di].flags,0        ;clear flags (i.e. DONE bit)
  310. send_pkt:
  311.     int_pkt
  312.     jnc    pkt_sent_ok
  313.     jmp    pkt_sent_bad
  314. pkt_sent_ok:
  315.     pop    dx
  316.     pop    ax
  317.     sub    ax,1            ;decrement low word
  318.     sbb    dx,0            ;decrement high word
  319.     mov    bx,ax            ;check if we reached zero
  320.     or    bx,dx
  321.     jne    send_again        ;we didn't
  322.  
  323. check_repeat:
  324.     cmp    repeat_switch,0        ;did they ask for repeat sending?
  325.     jne    send_repeat
  326.  
  327.     mov    dx,offset sending_msg
  328.     mov    ah,9
  329.     int    21h
  330.  
  331.     mov    ah,0            ;read a key.
  332.     int    16h
  333.     cmp    al,' '
  334.     je    load_count        ;a space -- send again.
  335.     jmp    short send_done
  336.  
  337. send_repeat:
  338.     cmp    quiet_switch,0
  339.     jne    chrout_done
  340.     mov    al,'T'
  341.     call    chrout
  342.  
  343. chrout_done:
  344.     cmp    packet_flag,0
  345.     je    no_packet
  346.  
  347.     mov    al,'R'
  348.     call    chrout
  349.  
  350.     mov    packet_flag,0
  351.  
  352. no_packet:
  353.     mov    ah,1            ;check for any key.
  354.     int    16h
  355.     jne    got_key
  356.     jmp    load_count        ;no key -- keep waiting.
  357.  
  358. got_key:
  359.     mov    ah,0            ;read a key.
  360.     int    16h
  361.  
  362. send_done:
  363.     mov    ah,3            ;release the handle.
  364.     mov    bx,handle
  365.     int_pkt
  366.     call    fatal_error
  367.  
  368.     mov    di,offset our_buffer + GIANT * 2
  369.     inc    di
  370.     and    di,not 1
  371.     push    cs
  372.     pop    es
  373. compare_memory:
  374.     mov    ax,055aah        ;compare a segment against 055aah.
  375.     mov    cx,di
  376.     neg    cx
  377.     shr    cx,1
  378.     scasw
  379.     jne    memory_bad
  380.     sub    cx,2
  381.     repe    scasw
  382.     jne    memory_bad
  383.     mov    ax,es
  384.     add    ax,1000h
  385.     mov    es,ax
  386.     add    ax,1000h
  387.     cmp    ax,phd_memsize        ;don't go past the end of memory.
  388.     jbe    compare_memory
  389.  
  390.     int    20h
  391. pkt_sent_bad:
  392.     call    print_error
  393.  
  394.     mov    ah,3            ;release the handle.
  395.     mov    bx,handle
  396.     int_pkt
  397.     call    fatal_error
  398.  
  399.     int    20h
  400.  
  401. memory_bad:
  402.     mov    dx,offset mem_trashed_msg
  403.     mov    ah,9
  404.     int    21h
  405.     mov    ax,es
  406.     call    wordout
  407.     mov    al,':'
  408.     call    chrout
  409.     mov    ax,di
  410.     dec    ax
  411.     call    wordout
  412.     mov    dx,offset crlf_msg
  413.     mov    ah,9
  414.     int    21h
  415.     int    20h
  416.  
  417. no_signature_err:
  418.     mov    dx,offset no_signature_msg
  419.     mov    ah,9
  420.     int    21h
  421.     int    20h
  422.  
  423.  
  424. our_recv:
  425.     or    ax,ax            ;first or second call?
  426.     jne    our_recv_1        ;second -- we ignore the packet
  427.     cmp    cs:packet_flag,0    ;Do we already have one?
  428.     jne    our_recv_2        ;yes - return zero.
  429.     push    cs
  430.     pop    es
  431.     mov    di,offset our_buffer + GIANT
  432.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  433. our_recv_2:
  434.     xor    di,di
  435.     mov    es,ax
  436.     mov    cx,0
  437.     loop    $
  438.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  439. our_recv_1:
  440.     inc    cs:packet_flag
  441.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  442.  
  443.  
  444.     include    pkterr.asm
  445.     include    getnum.asm
  446.     include    getdig.asm
  447.     include    skipblk.asm
  448.     include    chrout.asm
  449.     include    digout.asm
  450.  
  451. our_buffer    label    byte
  452.  
  453. code    ends
  454.  
  455.     end    start
  456.